package cn.zmx;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

public class Servlet extends HttpServlet {

    private ServletConfig config;
    @Override
    public void init(ServletConfig config) throws ServletException {
        this.config = config;
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("doPost()....");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("doGet()....");
        String encoding = config.getServletContext().getInitParameter("encoding");
        response.setContentType("text/html;charset="+encoding);
        System.out.println(encoding);
        config.getServletContext().setAttribute("str","hello");
        /*String value1 = config.getInitParameter("param1");
        String value2 = config.getInitParameter("param2");
        System.out.println(value1);
        System.out.println(value2);
        String value3 = config.getInitParameter("param3");
        System.out.println(value3);

        Enumeration<String> em = config.getInitParameterNames();
        while (em.hasMoreElements()){
            String param = em.nextElement();
            String value = config.getInitParameter(param);
            System.out.println(param+":"+value);
        }*/
    }
}
